<!DOCTYPE html>
<html lang="ja">
<head>
   <meta charset="UTF-8">
   <title>Start with pixi.js</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.4.3/pixi.min.js"></script>
<script type="text/javascript">
//别名（Aliases）
var Container = PIXI.Container,
    autoDetectRenderer = PIXI.autoDetectRenderer,
    loader = PIXI.loader,
    resources = PIXI.loader.resources,
    TextureCache = PIXI.utils.TextureCache,
    Sprite = PIXI.Sprite;

//基础代码
var stage = new Container(),
    renderer = autoDetectRenderer(256, 256);
document.body.appendChild(renderer.view);

//读取文件的路径设置与读取后执行的函数
loader
  .add("images/animals.json")
  .load(setup);


function setup() {
    var id = resources["images/animals.json"].textures;

    // 猫
    var cat = new Sprite(id["cat.png"]);
    cat.position.set(16, 16);

    // 刺猬
    var hedgehog = new Sprite(id["hedgehog.png"]);
    hedgehog.position.set(32, 32);

    // 老虎
    var tiger = new Sprite(id["tiger.png"]);
    tiger.position.set(64, 64);

    // 被称之为动物的类别
    var animals = new Container();

    // 把动物们塞进去
    animals.addChild(cat);
    animals.addChild(hedgehog);
    animals.addChild(tiger);

    animals.position.set(64, 64);

    stage.addChild(animals);
    renderer.render(stage);

    console.log(animals.toGlobal(cat.position));
    console.log(cat.parent.toGlobal(cat.position));

    // 也可以这么写
    console.log(tiger.getGlobalPosition().x);
    console.log(tiger.getGlobalPosition().y);

    // sprite.toLocal(sprite.position, anyOtherSprite)

    console.log(tiger.toLocal(tiger.position, hedgehog).x);
    console.log(tiger.toLocal(tiger.position, hedgehog).y);
}

</script>
</body>
</html>